package vip.wangwenhao.example.controller;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vip.wangwenhao.example.document.UserDocument;
import vip.wangwenhao.query.BaseQuery;
import vip.wangwenhao.example.service.UserEsService;
import vip.wangwenhao.page.PageResult;

import java.util.List;

/**
*  
*
* @author wwh
*
*/

@RestController
@RequestMapping("user")
@Slf4j
public class UserController {

    @Autowired
    private UserEsService userEsService;

    @RequestMapping("index")
    public void index(UserDocument userDocument){
        userEsService.index(userDocument);
    }

    @GetMapping("queryAll")
    public List<UserDocument> queryAll(){
        return userEsService.queryAll();
    }

    @GetMapping("queryForList")
    public List<UserDocument> queryForList(UserDocument userDocument){
        return userEsService.queryForList(userDocument);
    }
    @GetMapping("queryForPage")
    public PageResult<UserDocument> queryForPage(@RequestBody BaseQuery<UserDocument> userQuery){
        return userEsService.queryForPage(userQuery);
    }

    @GetMapping("query")
    public PageResult<UserDocument> query(@RequestBody BaseQuery<UserDocument> userQuery){
        log.warn("userQuery:{}", JSONObject.toJSONString(userQuery));
        return userEsService.query(userQuery);
    }

    @GetMapping("{id}")
    public UserDocument get(@PathVariable("id") String id){
        return userEsService.get(id);
    }
    @DeleteMapping("{id}")
    public Boolean delete(@PathVariable("id") String id){
        return userEsService.delete(id);
    }

}